const mongoose = require('mongoose')
mongoose.connect('mongodb://localhost/xia',{ useNewUrlParser: true})
.then(() => {
    console.log('服务器连接成功')
    //创建集合规则
    const courseSchema = new mongoose.Schema({
        name: String,
        author: String,
        isPublic: Boolean,
        age: Number
    })
    //使用规则创建集合
    const Course = mongoose.model('Course', courseSchema)

    // Course.find({_id:'61288f41e8389521704f3e7b'})
    // Course.findOne({name:'夏天'})
    // Course.find({age: {$gt:19}})
    // Course.find({author: {$in:['燕灵路']}})
    // Course.find().select('name age -_id')
    // Course.find().sort('-age')
    // Course.find().skip(2).limit(1)
    // Course.findOneAndDelete({name:'夏天'})
    // Course.deleteMany({name:'夏艺兮'})
    Course.updateOne({_id:'61288f41e8389521704f3e7b'}, {name:'夏艺兮',age:'2'})
    .then(res => {
        console.log(res)
    },err => {
        console.log(err)
    })
} )
.catch(err => console.log('服务器连接失败', err) )



// const course = new Course({
//     name: '夏天',
//     author: 'self',
//     isPublic: true
// })

// course.save()
// console.log(Course.find({name:'夏天'}))

// .then(res => {
//     console.log(res)
// })
